package io.renren.modules.sys.security.user;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @author Clown
 * @Date 2021-08-28 23:58
 */
public class SecurityUser {

    public static SysUserDetails getUser(){
        SysUserDetails userDetails;
        try {
            userDetails = (SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        }catch (Exception e){
            return null;
        }

        return userDetails;
    }

    public static Long getUserId(){
        return getUser().getUserId();
    }
}
